package com.wtwd.device.controller;


import com.wtwd.device.constant.RespCode;
import com.wtwd.device.model.dto.GetDialByWatchIdAndGroupIdDto;
import com.wtwd.device.model.dto.GetGroupInfoByWatchIdDto;
import com.wtwd.device.model.entity.DialManagement;
import com.wtwd.device.model.vo.GroupInfoVo;
import com.wtwd.device.model.vo.ResultVO;
import com.wtwd.device.service.ManagementService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author mjy
 * 平台服务与app服务成功code与失败code反了故注意远程调用返回
 * @date 2023/01/07
 * @description
 */
@Api(tags = "app表盘分组")
@RequestMapping("/app-dial-group")
@RestController
public class AppDialGroupController {

    @Resource
    private ManagementService managementService;


    /**
     * 根据手表id获取表盘分组
     *
     * @param getGroupInfoByWatchIdDto
     * @return
     */
    @ApiOperation(value = "获取该用户所有分组,并获取按规则获取分组里面的图片", notes = "")
    @PostMapping("/getGroupInfoByWatchId")
    public ResultVO<List<GroupInfoVo>> getGroupInfoByWatchId(@RequestBody GetGroupInfoByWatchIdDto getGroupInfoByWatchIdDto) {
        if (getGroupInfoByWatchIdDto == null || StringUtils.isBlank(getGroupInfoByWatchIdDto.getWatchId())) {
            return ResultVO.error(RespCode.PARAMS_ERROR);
        }
        ResultVO<List<GroupInfoVo>> resultVO = managementService.getGroupInfoByWatchId(getGroupInfoByWatchIdDto);
        if (resultVO.getCode().equals(RespCode.ERROR_CODE)) {
            return ResultVO.success(resultVO.getData());
        } else {
            return ResultVO.error();
        }
    }


    /**
     * 根据表盘id和分组id,获取表盘
     *
     * @param dao
     * @return
     */
    @ApiOperation(value = "根据表盘id和分组id,获取表盘", notes = "")
    @PostMapping("/getDialByWatchIdAndGroupIdPage")
    public ResultVO<List<DialManagement>> getDialByWatchIdAndGroupIdPage(@RequestBody GetDialByWatchIdAndGroupIdDto dao) {
        ResultVO<List<DialManagement>> resultVO = managementService.getDialByWatchIdAndGroupIdPage(dao);
        if (resultVO.getCode().equals(RespCode.ERROR_CODE)) {
            return ResultVO.success(resultVO.getData());
        } else {
            return ResultVO.error();
        }
    }


}
